package com.example.smartcity1.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.smartcity1.R;
import com.example.smartcity1.bean.ParklotListBean;

import java.util.List;

public class ParklotListAdapter extends ArrayAdapter<ParklotListBean.RowsDTO> {



    public ParklotListAdapter(@NonNull Context context, int resource, @NonNull List<ParklotListBean.RowsDTO> objects) {
        super(context, resource, objects);
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_parklot_list, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.parkNameText = convertView.findViewById(R.id.plateNumber_text);
            viewHolder.distanceText = convertView.findViewById(R.id.monetary_text);
            viewHolder.vacancyText = convertView.findViewById(R.id.entryTime_text);
            viewHolder.ratesText = convertView.findViewById(R.id.outTime_text);
            viewHolder.addressText = convertView.findViewById(R.id.parkName_text);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        ParklotListBean.RowsDTO item = getItem(position);
        viewHolder.parkNameText.setText(item.getParkName());
        viewHolder.distanceText.setText(item.getDistance() + " 公里");
        viewHolder.vacancyText.setText("空位 " + item.getVacancy());
        viewHolder.ratesText.setText("停车费" + item.getRates() + "元／小时");
        viewHolder.addressText.setText(item.getAddress());
        return convertView;
    }

    private class ViewHolder {
        TextView parkNameText;
        TextView distanceText;
        TextView vacancyText;
        TextView ratesText;
        TextView addressText;
    }
}
